using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Order.Dto;
using JTZY.Model.Order;
using JTZY.Service.Order.IOrderService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2025-02-16
namespace JTZY.Admin.WebApi.Controllers.Order
{
    /// <summary>
    /// 退货单表
    /// </summary>
    [Verify]
    [Route("order/Corecmsbillreship")]
    public class CorecmsbillreshipController : BaseController
    {
        /// <summary>
        /// 退货单表接口
        /// </summary>
        private readonly ICorecmsbillreshipService _CorecmsbillreshipService;

        public CorecmsbillreshipController(ICorecmsbillreshipService CorecmsbillreshipService)
        {
            _CorecmsbillreshipService = CorecmsbillreshipService;
        }

        /// <summary>
        /// 查询退货单表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "corecmsbillreship:list")]
        public IActionResult QueryCorecmsbillreship([FromQuery] CorecmsbillreshipQueryDto parm)
        {
            parm.UserId= HttpContext.GetUId();
            var response = _CorecmsbillreshipService.GetList(parm);
            return SUCCESS(response);
        }

        [HttpGet("getstatistics")]
        [ActionPermissionFilter(Permission = "corecmsbillreship:list")]
        public IActionResult GetStatistics([FromQuery] CorecmsbillreshipQueryDto parm)
        {
            parm.UserId = HttpContext.GetUId();
            var response = _CorecmsbillreshipService.GetStatistics(parm);
            return SUCCESS(response);
        }       

        /// <summary>
        /// 查询退货单表详情
        /// </summary>
        /// <param name="ReshipId"></param>
        /// <returns></returns>
        [HttpGet("{ReshipId}")]
        [ActionPermissionFilter(Permission = "corecmsbillreship:query")]
        public IActionResult GetCorecmsbillreship(string ReshipId)
        {
            var response = _CorecmsbillreshipService.GetInfo(ReshipId);
            
            var info = response.Adapt<CorecmsbillreshipDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加退货单表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "corecmsbillreship:add")]
        [Log(Title = "退货单表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCorecmsbillreship([FromBody] CorecmsbillreshipDto parm)
        {
            var modal = parm.Adapt<Corecmsbillreship>().ToCreate(HttpContext);

            var response = _CorecmsbillreshipService.AddCorecmsbillreship(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新退货单表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "corecmsbillreship:edit")]
        [Log(Title = "退货单表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCorecmsbillreship([FromBody] CorecmsbillreshipDto parm)
        {
            var modal = parm.Adapt<Corecmsbillreship>().ToUpdate(HttpContext);
            var response = _CorecmsbillreshipService.UpdateCorecmsbillreship(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除退货单表
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "corecmsbillreship:delete")]
        [Log(Title = "退货单表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCorecmsbillreship([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<string>(ids);

            return ToResponse(_CorecmsbillreshipService.Delete(idArr));
        }

    }
}